#include "worksheetmanager.h"

static FILE * Pita;
boolean end;
string cString;

void Baca_WorkSheet (string WS, Sheet *S)
/* Membaca file tempat disimpannya data untuk kemudian dimasukkan ke dalam struktur data */
{
	string Isi, Col;
	int nBaris=0;
	string Pos;
	printf("masuk sini gan !!\n");
	printf("buka file : %s\n",WS.s);
	Pita = fopen(WS.s, "r");
	CreateEmpty(S);
	while (nBaris != 1) {
		StartString(Pita);
		Isi.length=0;
		nBaris = 1;
		if (!end)
		{
			Col = cString;
			AdvString(Pita); 
			nBaris = nBaris + 1;
			Pos = StrCat(Col,cString);
			AdvString(Pita);
			nBaris = nBaris + 1;
			AdvString(Pita);
			nBaris = nBaris + 1;
			Isi=StrCat(Isi,cString);
			while (!end)
			{	
				AdvString(Pita);
				Isi=StrCat(Isi,cString);
				//Isi = cString;
			}
		}
		//Isi=StrCat(Isi,cString);
		if (nBaris!=1)
			{InsertXY(S,Pos,Isi);}
	} 
	fclose(Pita);
}

void Close_Worksheet (string WS, Sheet S)
{
	addressR Pr;
	address P;
	int retval;
	
	Pita = fopen(WS.s, "w");
	
	Pr = NextBrsOri(S);
	while (Pr != Nil)
	{
		P = FirstBrs(Pr);
		while (P != Nil)
		{
			retval = fprintf(Pita, "%s ", AdrCol(P).s);
			retval = fprintf(Pita, "%d :", AdrBrs(P));
			retval = fprintf(Pita, " %s", InfoChar(P).s);
			retval = fprintf(Pita, "%c\n", '#');
			P = NextCol(P);
		}
		Pr = NextHR(Pr);
	}
	retval = fprintf(Pita, "%c\n", '#');
	fclose(Pita);
}
